package com.pxst.scheduled;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pxst.fi.entity.SysBankBillWaitEntity;
import com.pxst.fi.mapper.SysBankBillWaitMapper;
import com.pxst.fi.service.SysBankBillWaitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * @author rj
 * @create 2023-10-24-18:42
 */
@Component
@Slf4j
public class DelScheduled {

    @Autowired
    private SysBankBillWaitMapper bankBillWaitMapper;

    /**
     * 清除过期的银行待对账数据
     */
    public void cleanExpiredSysBankBillWait() {
        // 获取当前日期时间
        Date currentDate = new Date();

        // 创建一个Calendar对象并设置为当前日期时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);

        // 将日期往前推7天
        calendar.add(Calendar.DAY_OF_YEAR, -7);

        // 获取七天前的日期
        Date sevenDaysAgo = calendar.getTime();

        int delete = bankBillWaitMapper.delete(new LambdaQueryWrapper<SysBankBillWaitEntity>()
                .lt(SysBankBillWaitEntity::getTime, sevenDaysAgo));
        if (delete > 0){
            log.info("清除过期的银行待对账数据成功，清除了【" + delete + "】条数据");
        }
    }
}
